# include <stdlib.h>
# include <stdio.h>

# include "StudentInfo.h"
# include "StudentGrade.h"
# include "Student.h"
# include "Manip.h"

# define ALL_DISP_FORMAT %s %s %s %d %d %d %d
# define ALL_DISP_PARA ps_tmp->pi->number, ps_tmp->pi->name, ps_tmp->pi->address, ps_tmp->pi->age, ps_tmp->pg->maths, ps_tmp->pg->clang, ps_tmp->pg->english

PSTUDENT
Construct (void)
{
	PSTUDENT ps = (PSTUDENT)malloc (sizeof (STUDENT));
	ps->pnext = NULL;
	return ps;
}
void
Add (PSTUDENT phead, PINFO pi_in, PGRADE pg_in)
{
	PSTUDENT ps = (PSTUDENT)malloc (sizeof (STUDENT));
	PSTUDENT ps_tmp = phead;
	ps->pi = pi_in;
	ps->pg = pg_in;
	while (ps_tmp->pnext != NULL)
	{
		ps_tmp = ps_tmp->pnext;
	}
	ps_tmp->pnext = ps;
	ps->pnext = NULL;
}
void
Display (PSTUDENT phead)
{
	PSTUDENT ps_tmp = phead;
	while (ps_tmp != NULL)
	{
		if (ps_tmp == phead)
			;
		else
		{
			printf ("%s %s %s %d %d %d %d\n", ps_tmp->pi->number, ps_tmp->pi->name, ps_tmp->pi->address, ps_tmp->pi->age, ps_tmp->pg->maths, ps_tmp->pg->clang, ps_tmp->pg->english);//Access violation
		}
			ps_tmp = ps_tmp->pnext;
	}
}
void
Destroy (PSTUDENT phead)
{
	PSTUDENT ps_tmp = phead;
	while (ps_tmp != NULL)
	{
		if (ps_tmp == phead)
			;
		else
		{	free (ps_tmp->pg);
			free (ps_tmp->pi);
		}
		ps_tmp = ps_tmp->pnext;
	}
}
PMANIP
InitManip (void)
{
	PMANIP pm = (PMANIP)malloc (sizeof (MANIP));
	pm->Construct = Construct;
	pm->Add = Add;
	pm->Display = Display;
	pm->Destroy = Destroy;

	return pm;
}